//
// Created by Asus on 2025/5/31.
//

#include <iostream>
#include <bits/ostream.tcc>
using namespace std;

void demo01() {
    int score[10];
    for (int i = 0; i < 10; i++) {
        cout << "i:" << score[i] << endl;
    }
    score[0] = 100;
    score[1] = 99;
    score[2] = 85;

    //利用下标输出
    cout << score[0] << endl;
    cout << score[1] << endl;
    cout << score[2] << endl;

    int score2[10] = {1};
    for (int i = 0; i < 10; i++) {
        cout << "i:" << score2[i] << endl;
    }
    int score3[] = {100, 90, 80, 70, 60, 50, 40, 30, 20, 10};
}

void demo02() {
    int arr[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    cout << "arr size:" << sizeof(arr) << endl;
    cout << "arr[0] size:" << sizeof(arr[0]) << endl;
    cout << "数组元素个数：" << sizeof(arr) / sizeof(arr[0]) << endl;
}

void demo03() {
    //方式1
    //数组类型 数组名 [行数][列数]
    int arr[2][3];
    arr[0][0] = 1;
    arr[0][1] = 2;
    arr[0][2] = 3;
    arr[1][0] = 4;
    arr[1][1] = 5;
    arr[1][2] = 6;

    //方式2
    //数据类型 数组名[行数][列数] = { {数据1，数据2 } ，{数据3，数据4 } };
    int arr2[2][3] =
    {
        {1, 2, 3},
        {4, 5, 6}
    };

    int arr3[2][3] = {1, 2, 3, 4, 5, 6};
    // for (int i = 0; i < 2; i++) {
    //     for (int j = 0; j < 3; j++) {
    //         cout << "arr[" << i <<"][" << j  << "]" <<  arr[i][j] << endl;
    //     }
    // }

    int arr4[][3] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cout << "arr[" << i << "][" << j << "]" << arr4[i][j] << endl;
        }
    }
}

void demo04() {
    int arr0[] = {1, 2, 4, 5};
    int index = 0;
    while (arr0[index] != '\0') {
        index++;
    }
    cout << "index:" << index << endl;
    int arr[2][3] = {{1, 2, 3}, {4, 5, 6}};
    cout << "arr size:" << sizeof(arr) << endl;
    cout << "arr[0] size:" << sizeof(arr[0]) << endl;
    cout << "arr[0][0] size:" << sizeof(arr[0][0]) << endl;

    cout << "二维数组行数：" << sizeof(arr) / sizeof(arr[0]) << endl;
    cout << "二维数组列数：" << sizeof(arr[0]) / sizeof(arr[0][0]) << endl;

    cout << "二维数组首地址：" << arr << endl;
    cout << "二维数组第一行地址：" << arr[0] << endl;
    cout << "二维数组第二行地址：" << arr[1] << endl;

    // 二维数组第一个元素地址：0xf1f4bff6d0
    // 二维数组第二个元素地址：0xf1f4bff6d4 +4
    cout << "二维数组第一个元素地址：" << &arr[0][0] << endl;
    cout << "二维数组第二个元素地址：" << &arr[0][1] << endl;
    int *p = *arr;
    cout << p << endl;
    cout << "p[0]:" << p[0] << endl;
    cout << "p[5]:" << p[5] << endl;
    cout << "*p:" << *p << endl;
    cout << "*p:" << *++p << endl;
    cout << "*p:" << *++p << endl;
    cout << "*p:" << *++p << endl;
    // arr 本质是指向第一行的指针，类型为 int(*)[3]
    int (*p2)[3] = arr;
    cout << "p2:" << p2 << endl;
    cout << "*p2:" << p2[0][0] << endl;
    cout << "*p2:" << p2[1][0] << endl;

    cout << **arr << endl; // 解引用两次，输出: 1
    cout << *arr << endl; // 第一行地址
    cout << *(arr + 1) << endl; // 第二行地址
    cout << *(*arr + 1) << endl; // 第一行第3个元素，输出: 3
    cout << **(arr + 1) << endl; // 第二行第一个元素，输出: 4
    cout << *(*(arr + 1)+2) << endl; // 第二行第三个元素
}

int main() {
    // demo01();
    // demo02();
    // demo03();
    demo04();
    return 0;
}
